﻿Namespace Catalog.Search
    ''' <summary>
    ''' The track similar call is used to retrieve similar tracks for the ones specified by running them through BeatBot.
    ''' </summary>
    Public Class TracksSimilarQuery
        Inherits Query
        ''' <summary>
        ''' Filter tracks by a list of numeric ids.
        ''' </summary>
        Public Property Ids As List(Of Integer)

        Public Sub New()
            MyBase.New()
            Me.Ids = New List(Of Integer)
        End Sub

        Public Sub New(id As Integer)
            Me.New()
            Me.Ids.Add(id)
        End Sub

        Public Sub New(ids As IEnumerable(Of Integer))
            Me.New()
            Me.Ids.AddRange(ids)
        End Sub

        Public Overrides Function GetUrl() As System.Uri
            Dim url As String = Beatport.CATALOG_TRACK_SIMILAR_URL
            Dim queryStr As New List(Of String)

            If Me.Ids.Count > 0 Then
                queryStr.Add(String.Format("id{0}={1}", If(Me.Ids.Count > 1, "s", ""), String.Join(",", Me.Ids.ToArray)))
            End If

            If Me.PageSize > 0 Then
                queryStr.Add(String.Format("perPage={0}&page={1}", Me.PageSize, Me.Page))
            End If

            If queryStr.Count > 0 Then
                url = String.Format("{0}?{1}", url, String.Join("&", queryStr.ToArray))
            End If

            Return New Uri(url)
        End Function
    End Class
End Namespace